#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_ads \
--username root \
--password 123456 \
--query 'SELECT id, product_id, material_id, group_id, ad_name, materail_url FROM jtp_ads.ads WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/app_ads/ads/${data_date}" \
--as-textfile \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_ads \
--username root \
--password 123456 \
--query 'SELECT id, ad_id, platform_id, create_time, cancel_time FROM jtp_ads.ads_platform WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/app_ads/ads_platform/${data_date}" \
--as-textfile \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_ads \
--username root \
--password 123456 \
--query 'SELECT id, name, price FROM jtp_ads.product WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/app_ads/product/${data_date}" \
--as-textfile \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_ads \
--username root \
--password 123456 \
--query 'SELECT id, platform, platform_alias_zh FROM jtp_ads.platform_info WHERE $CONDITIONS AND 1 = 1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/app_ads/platform_info/${data_date}" \
--as-textfile \
--fields-terminated-by '\001' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'